*Table A.33: Means of baseline diet intake for those present at the start and in year 3
cd ""

use master_data_adults_child_s13456_shared.dta, clear

*Calculate z-scores for BMI
egen gendermax=max(gender), by(id_nb)
ge sex=(gendermax==1) 
replace sex=. if gendermax==.

drop zbmi pzbmi
egen zbmi = zanthro(bmi,ba,UK), xvar(months) gender(sex) gencode(male=1, female=0) ageunit(month)
gen pzbmi=normal(zbmi)

ge overw_obese_child=(pzbmi>=0.85)
replace overw_obese_child=. if pzbmi==.  

ge uwgt_child=(pzbmi<=0.02)
replace uwgt_child=. if pzbmi==.

*
ge food15_other_veg_new=food15_other_veg
replace food15_other_veg_new=0 if food15_other_veg==. & energykcal!=.

ge food16_fruit_new=food16_fruit
replace food16_fruit_new=0 if food16_fruit==. & energykcal!=.

su food15_other_veg 
su food16_fruit 
su food15_other_veg_new 
su food16_fruit_new

*
drop portion_veg_wisp portion_fruit_wisp
gen portion_veg_wisp=food15_other_veg/80
gen portion_fruit_wisp=food16_fruit/80
gen fuit_and_veg_g=total_veg_fruit_eatwell if session==1
replace fuit_and_veg_g=total_veg_fruit_eatwell if session==3
replace fuit_and_veg_g=food15_other_veg+food16_fruit if session==4

ge FV=food15_other_veg_new+food16_fruit_new

keep id id_nb child treatment session energykcal food15_other_veg_new food16_fruit_new totalfatg saturatesg sugarsg nmesg pzbmi bmi_cat bmi fp_fruit fp_veg fp_meat_fish_egg fp_processed fp_sweets fp_bread fp_cheese FV

ge t=1 if session==1
replace t=2 if session==3
replace t=3 if session==4
replace t=4 if session==5
replace t=5 if session==6

merge 1:1 id t using "panel.dta"

egen child1=max(child), by(id)
drop child
rename child1 child

drop if t==.
drop session
drop _merge

ge pres_24hr=1 if food16_fruit_new!=.
replace pres_24hr=0 if  food16_fruit_new==.
egen count_sum_24hr=sum(pres_24hr), by(id)

ge pres_bmi=1 if bmi_cat!=.
replace pres_bmi=0 if  bmi_cat==.
egen count_sum_bmi=sum(pres_bmi), by(id)

ge pres_fp=1 if fp_veg!=.
replace pres_fp=0 if  fp_veg==.
egen count_sum_fp=sum(pres_fp), by(id)

gen count_all=count_sum_fp+count_sum_bmi+count_sum_24hr
drop if count_all==0

sort count_all

reshape wide pres_24hr pres_bmi pres_fp treatment child pzbmi energykcal food15_other_veg_new food16_fruit_new totalfatg saturatesg sugarsg nmesg bmi_cat bmi fp_fruit fp_veg fp_meat_fish_egg fp_processed fp_sweets fp_bread fp_cheese FV, i(id_nb) j(t)

***Intake
**Children
*Control
foreach x in FV1 energykcal1 food15_other_veg_new1 food16_fruit_new1 totalfatg1 saturatesg1 sugarsg1 nmesg1 {
reg `x' if child1==1 & pres_24hr1==1 & (treatment1==1)
est store eq1
reg `x' if child1==1 & pres_24hr5==1 & (treatment1==1)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
su `x' 
}

*Meal
foreach x in FV1 energykcal1 food15_other_veg_new1 food16_fruit_new1 totalfatg1 saturatesg1 sugarsg1 nmesg1 {
reg `x' if child1==1 & pres_24hr1==1 & (treatment1==2)
est store eq1
reg `x' if child1==1 & pres_24hr5==1 & (treatment1==2)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
su `x' 
}

*Snack
foreach x in FV1 energykcal1 food15_other_veg_new1 food16_fruit_new1 totalfatg1 saturatesg1 sugarsg1 nmesg1 {
reg `x' if child1==1 & pres_24hr1==1 & (treatment1==3)
est store eq1
reg `x' if child1==1 & pres_24hr5==1 & (treatment1==3)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
su `x' 
}


**Adults
*Control
foreach x in FV1 energykcal1 food15_other_veg_new1 food16_fruit_new1 totalfatg1 saturatesg1 sugarsg1 nmesg1 {
reg `x' if child1==0 & pres_24hr1==1 & (treatment1==1)
est store eq1
reg `x' if child1==0 & pres_24hr5==1 & (treatment1==1)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
su `x' 
}


*Meal
foreach x in FV1 energykcal1 food15_other_veg_new1 food16_fruit_new1 totalfatg1 saturatesg1 sugarsg1 nmesg1 {
reg `x' if child1==0 & pres_24hr1==1 & (treatment1==2)
est store eq1
reg `x' if child1==0 & pres_24hr5==1 & (treatment1==2)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
su `x' 
}

*Snack
foreach x in FV1 energykcal1 food15_other_veg_new1 food16_fruit_new1 totalfatg1 saturatesg1 sugarsg1 nmesg1 {
reg `x' if child1==0 & pres_24hr1==1 & (treatment1==3)
est store eq1
reg `x' if child1==0 & pres_24hr5==1 & (treatment1==3)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
su `x' 
}
